<style lang="less">
	/*@import './international.less';*/
</style>

<template>
	<div>
		<!--<Checkbox v-bind="checkbox" @click="checkAll(checkbox.value)">全选</Checkbox>-->
		<Row :gutter="8">
			<slot>

			</slot>
			<slot name="buttons">
				<Button type="primary" @click="onSearch">查询</Button>
				<Button type="warning" @click="clear">清空</Button>
			</slot>
		</Row>
	</div>
</template>

<script>
    // 搜索条件
    import util from '@/libs/util';
    import _ from 'lodash';

    export default {
        data () {
            return {
                name: 'searchbar',
                copyQueryParams: null
            }
        },
        methods: {
            clear(){ // 清空参数值
                for (let k in this.queryParams) {
                    if (util.oneOf(k, ["count", "pageSize", "pageNum"])) {
                        continue;
                    }
                    if (this.copyQueryParams[k] === undefined) {
                        this.queryParams[k] = undefined;
                    } else {
                        this.queryParams[k] = _.cloneDeepWith(this.copyQueryParams[k]);
                    }
                }
                this.$emit("searchbarClear");
            },
            onSearch(){ // 触发查询事件
                this.$emit("onSearch");
            }
        },
        props: {
            queryParams: { // slot里input的值的集合
                type: Object,
                default: {}
            }
        },
        mounted() {
            this.copyQueryParams = _.cloneDeepWith(this.queryParams);
        }
    }
</script>